<%--
  Created by IntelliJ IDEA.
  User: kuibu
  Date: 16/2/17
  Time: 上午5:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="en">
<head>
    <!--<meta name="viewport" content="width=device-width, initial-scale=1"/>-->
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title></title>
    <script src="http://www.kuibutech.com/kuibuversion1/js/jquery-1.7.1.js"></script>

    <link rel="stylesheet" type="text/css" href="http://www.kuibutech.com/kuibuversion1/css/sweetalert.css">
    <script src="http://www.kuibutech.com/kuibuversion1/js/sweetalert.min.js"></script>
    <script>
        $(document).ready(function () {
            if(check()){
                $("#subBtn").bind("click", submitInvite);
            }

        });

        function check() {
            var hasInputInviteCode = document.getElementById("hasInputInviteCode").value;
            if (hasInputInviteCode == "true") {
                $("#subBtn").bind("click", alertHasInput);
                return false;
            }else{
                return true;
            }

        }

        function alertHasInput() {
            swal({
                title: "",
                text: "<span style=\"color:red;font-size: 20px\">您已经填写过邀请码！<span>",
                html: true,
                allowOutsideClick:true,
                showConfirmButton:true
            });
        }

        function submitInvite() {
            var inviteCode = document.getElementById("inviteCode").value;
            var userId = document.getElementById("userId").value;
            if (inviteCode == "") {
                swal({
                    title: "",
                    text: "<span style=\"color:red;font-size: 20px\">请输入邀请码再进行提交<span>",
                    html: true,
                    allowOutsideClick:true,
                    showConfirmButton:true
                });
            } else {
                $.post("/kuibuversion1/share/submitInvite", {inviteCode: inviteCode, userId: userId}, function (data) {
                    if (data.result == true) {
//                        $("#success").css("display", "inline");
//                        $("#subBtn").attr('disabled',true);
                        swal({
                            title: "邀请码添加成功",
                            text: "<span style=\"color:red;font-size: 20px\">您也可以将跬步分享给您的好友哦！<span>",
                            html: true,
                            allowOutsideClick:true,
                            showConfirmButton:true
                        });
                    } else {
                        swal({
                            title: "邀请码添加失败",
                            text: "<span style=\"color:red;font-size: 20px\">您的输入有误，再问问您的好友吧！<span>",
                            html: true,
                            allowOutsideClick:true,
                            showConfirmButton:true
                        });
                    }
                });
            }
        }

    </script>
</head>
<body>
<img style="width:100%; height:100%;" src="http://img.kuibutech.com/kbApp_fixedImage/yaoqing.jpg"/>
<form action="" method="post">
    <div style="position:absolute; height: 50px;width: 22%;margin-left: 48%;margin-top: -530px">
        <input id="inviteCode" style="width:100%;height:50px;background-color: transparent;font-size: 45px">
    </div>
    <input id="userId" hidden name="userId" value="${userId}">
    <input id="hasInputInviteCode" hidden value="${hasInputInviteCode}">
</form>
<div style="position:absolute; height: 50px;width: 24%;margin-left: 48%;margin-top: -670px;font-size: 45px">${inviteCode}</div>
<div style="position:absolute; height: 50px;width: 24%;margin-left: 48%;margin-top: -600px;font-size: 45px">${invitedFriends}</div>
<div id="subBtn" style="position:absolute; height: 50px;width: 15%;margin-left: 74%;margin-top: -530px"></div>
</body>


</html>
